import { NodeStatus } from "./NodeStatus";
import { INode } from "./interfaces/INode";
import { INodeConfig } from "./interfaces/INodeConfig";



export abstract class Node<T> implements INode<T> {

    /**名称 */
    name: string;

    /**父节点*/
    parent: INode<T> | null = null;

    /**黑板 */
    blackboard: T;

    /**状态 */
    private __status: NodeStatus = NodeStatus.IDLE;

    constructor(name: string, blackboard: T) {
        this.name = name;
        this.blackboard = blackboard;
    }

    Init(data: INodeConfig): void {

    }

    Evaluate(): NodeStatus {
        this.status = this.Tick() as NodeStatus;
        return this.status;
    }

    abstract Tick(): NodeStatus | Promise<NodeStatus>;

    abstract Halt(): void;

    Destroy(): void {
        this.parent = null;
    }

    /**获取状态*/
    get status(): NodeStatus {
        return this.__status;
    }

    set status(value: NodeStatus) {
        this.__status = value;
    }
}